//
//  ZYCTeachingAttendanceDetailHeaderView.m
//  ZDSC
//
//  Created by ZDTX on 2021/9/3.
//

#import "ZYCTeachingAttendanceDetailHeaderView.h"
#import "ZYCTeachingAttendanceDetailHeaderCell.h"
#import "ZYCTeachingAttendanceDetailModel.h"

@interface ZYCTeachingAttendanceDetailHeaderView ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;

@end
@implementation ZYCTeachingAttendanceDetailHeaderView

- (void)setModel:(ZYCTeachingAttendanceDetailModel *)model{
    _model = model;
    [self.tableView reloadData];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HEX_RGB(@"FFFFFF");
        [self addSubview:self.tableView];

        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];

    }
    return self;
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZYCTeachingAttendanceDetailHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZYCTeachingAttendanceDetailHeaderCell class]) forIndexPath:indexPath];
    cell.titleLabel.text = self.dataSource[indexPath.row];
    if (indexPath.row == 0) {//授课老师
        cell.contentLabel.text = self.model.userName;
    }else if(indexPath.row == 1){//听评课类型
        cell.contentLabel.text = self.model.listenClassTypeName;
    }else if(indexPath.row == 2){//听评课时间
        cell.contentLabel.text = self.model.mergeTime;
    }else if(indexPath.row == 3){//所属学科
        cell.contentLabel.text = self.model.subjectName;
    }else if(indexPath.row == 4){//授课班级
        cell.contentLabel.text = self.model.className;
    }else if(indexPath.row == 5){//课程状态
        cell.contentLabel.text = self.model.overFlagStr;
        if ([self.model.overFlag isEqualToString:@"before"]) {
            cell.contentLabel.textColor = HEX_RGB(@"#EB9F28");
        }else if ([self.model.overFlag isEqualToString:@"doing"]) {
            cell.contentLabel.textColor = HEX_RGB(@"#39A85B");
        }else if ([self.model.overFlag isEqualToString:@"after"]) {
            cell.contentLabel.textColor = HEX_RGB(@"#B9B9B9");
        }
    }
    return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 80.0f;
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 45.0f;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc] init];
    UILabel *titleLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 17.0f) titleColor:HEX_RGB(@"#262A28") textAlignment:ZZTextAlignmentLeft];
    titleLabel.numberOfLines = 0;
    titleLabel.text = self.model.title;
    [headerView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(headerView).offset(15.0f);
        make.right.bottom.equalTo(headerView).offset(-15.0f);
    }];
    return headerView;;
    
}


- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[ZYCTeachingAttendanceDetailHeaderCell class] forCellReuseIdentifier:NSStringFromClass([ZYCTeachingAttendanceDetailHeaderCell class])];
        _tableView.backgroundColor = HEX_RGB(kBgLightGrayColor);
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.scrollEnabled = NO;
        _tableView.sectionHeaderHeight = 45.0f;
        _tableView.estimatedSectionHeaderHeight = UITableViewAutomaticDimension;
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
    }
    return _tableView;
}


- (NSArray *)dataSource {
    if (!_dataSource) {
        _dataSource = @[@"授课老师:",@"听评课类型:",@"听评课时间:",@"所属学科",@"授课班级:",@"课程状态:"];
    }
    return _dataSource;
}
@end
